//
//  ViewController.m
//  TestHSYLoading
//
//  Created by Sean on 15/12/4.
//  Copyright (c) 2015年 seanhuang1661. All rights reserved.
//

#import "ViewController.h"
#import "HSYLoading.h"
#import "UIView+FY.h"
#import "HSYLoadingManage.h"

@interface ViewController ()

@property (nonatomic, strong) UIView *testView1;
@property (nonatomic, strong) UIView *testView2;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"test_bg"]]];
    
    self.testView1 = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frameHeight - 150, self.view.frameWidth / 2, 150)];
    [self.testView1 setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.testView1];
    
    self.testView2 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frameWidth / 2, self.view.frameHeight - 150, self.view.frameWidth / 2, 150)];
    [self.testView2 setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.testView2];
}

- (void)hideLoadingForView {
    [[HSYLoadingManage sharedInstance] hideLoadingWithKey:@"selfview"];
}

- (void)hideLoadingForWindow {
    [[HSYLoadingManage sharedInstance] hideLoadingForWindow];
}

- (IBAction)loadingForView:(id)sender {
    [[HSYLoadingManage sharedInstance] showLoadingForParentView:self.view withKey:@"selfview"];

    [self performSelector:@selector(hideLoadingForView) withObject:nil afterDelay:10.0];
}

- (IBAction)loadingForWindow:(id)sender {
    [[HSYLoadingManage sharedInstance] showLoadingForWindow];
    [self performSelector:@selector(hideLoadingForWindow) withObject:nil afterDelay:5.0];
}

- (IBAction)loadingForTestView1:(id)sender {
    
    [[HSYLoadingManage sharedInstance] showLoadingForParentView:self.testView1 withKey:@"testView1"];
    
    double delayInSeconds = 3.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [[HSYLoadingManage sharedInstance] hideLoadingWithKey:@"testView1"];
    });
}

- (IBAction)loadingForTestView2:(id)sender {
    
    [[HSYLoadingManage sharedInstance] showLoadingForParentView:self.testView2 withKey:@"testView2"];
    
    double delayInSeconds = 5.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [[HSYLoadingManage sharedInstance] hideLoadingWithKey:@"testView2"];
    });
}

@end
